'''
参考： https://blog.csdn.net/m0_37820268/article/details/124193063
5 5
0 1 0 0 0
0 1 1 1 0
0 0 0 0 0
0 1 1 1 0
0 0 0 1 0
'''
from typing import List

def walk(start_x: int, start_y: int, m: int, n: int, maze: List[int], pos=[(0, 0)]):
    '''
    因为数组、列表里取值的格式：[行][列]，所以先纵轴再横轴，
    x --> 纵轴 -->对应m
    y --> 横轴 -->对应n
    '''
    # print('start_x:', maze)
    if start_y + 1 < n and maze[start_x][start_y + 1] == 0:  # 向右
        # 逻辑可当做一直往右走，到尽头了或者碰到墙壁了就往左/上/下的方向走
        if (start_x, start_y + 1) not in pos:
            walk(start_x, start_y + 1, m, n, maze, pos + [(start_x, start_y + 1)])
    if start_y - 1 >= 0 and maze[start_x][start_y - 1] == 0:  # 向左
        if (start_x, start_y - 1) not in pos:
            walk(start_x, start_y - 1, m, n, maze, pos + [(start_x, start_y - 1)])

    if start_x + 1 < m and maze[start_x + 1][start_y] == 0:   # 向下
        if (start_x + 1, start_y) not in pos:
            walk(start_x + 1, start_y, m, n, maze, pos + [(start_x + 1, start_y)])
    if start_x - 1 >= 0 and maze[start_x - 1][start_y] == 0:  # 向上
        if (start_x - 1, start_y) not in pos:
            walk(start_x - 1, start_y, m, n, maze, pos + [(start_x - 1, start_y)])

    if (start_x, start_y) == (m - 1, n - 1): # 已经到终点了
        # 注意这里是进入了很多个函数嵌套的内部，所以这里的pos是包含很多内容的，
        # 完全不需要pos += [(sx,sy)]来改变初始的pos值
        for p in pos:
            print('(' + str(p[0]) + ',' + str(p[1]) + ')')

while True:
    try:
        m, n = list(map(int, input().split()))  # m行n列 m-->纵轴 n-->横轴
        maze = []
        for _ in range(m):
            maze.append(list(map(int,input().split()))) # 创建二维数组
        walk(0, 0, m, n, maze)
    except:
        break



